package com.xxx.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.xxx.common.UserAuth;
import com.xxx.common.dto.Menu;
import com.xxx.interceptor.AuthorityType;
import com.xxx.interceptor.UserAuthority;
import com.xxx.service.SysMenuService;

@Controller
@UserAuthority(authorityType = AuthorityType.NoAuthority)
public class ManageController {
	
	@Autowired
	private SysMenuService sysMenuService;
	
	/**
	 * 主页
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value={"/","index.html"})
	public ModelAndView index(HttpServletRequest request) throws Exception{
		ModelAndView mv = new ModelAndView("manage/index");
		//取菜单
		long userid = UserAuth.getUserid(request);	//判断权限
		Map<String, Object> whereMap = new HashMap<>();
		whereMap.put("status", 1);
		List<Menu> menuList = sysMenuService.getMenuList(whereMap, userid);
		mv.addObject("menulist", menuList);
		mv.addObject("username", UserAuth.getUsername(request));
		return mv;
	}
	
	/**
	 * 空页面 emptyPage 
	 * @param request
	 * @return
	 */
	@RequestMapping(value={"empty_page.html"})
	public ModelAndView emptyPage(HttpServletRequest request){
		ModelAndView mv = new ModelAndView("manage/empty_page");
	
		return mv;
	}
	
	@RequestMapping(value="manage/welcome.html")
	public String welcome(){
		Random random = new Random();
		int page = (random.nextInt(10) % 3) +1;
		return "manage/welcome/" + page;
	}
	
}
